<?php
	
	require_once 'config.php';
	
	class DBConnection {
		private $m_mysqli = NULL;
		
		public function Connect() {
			
			$password = "";
			$this->m_mysqli = new mysqli(DBSettings::DBHOST, DBSettings::DBUSER, DBSettings::DBPASSWORD, DBSettings::DATABASE);
			//Sätter charset före varje fråga
			$this->m_mysqli->set_charset("UTF8");
			
			//kollar uppkoppling
			if ($this->m_mysqli->connect_errno) {
				return FALSE;
			}
			
			else {

			}
			return true;
		}
		
		//Stänger uppkoppling
		public function Close() {
			$this->m_mysqli->close();
				$this->m_mysqli = NULL;
		}

		/**
		 * @return mysqli_stmt
		 */		
		public function Prepare($sql) {
			$stmt = $this->m_mysqli->prepare($sql);
			if ($stmt === FALSE) {
				echo "prepare av '$sql' misslyckades " . $this->m_mysqli->error;
				return false;
			}
			return $stmt;
		}
		
	}
